//
//  BaseHttpRequest.m
//  DianBa
//
//  Created by karl on 2018/8/20.
//  Copyright © 2018年 DianBa. All rights reserved.
//

#import "BaseHttpRequest.h"

@implementation BaseHttpRequest

+(void)requestWithUrl:(NSString *)url andParameter:(NSDictionary *)param success:(SuccessCompletionBlock)successBlock failure:(FailureCompletionBlock)failureBlock{
    
    NSString *urlString = [NSString stringWithFormat:@"%@%@",[DBManagement sharedInstance].hostUrl,url];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.operationQueue.maxConcurrentOperationCount = 4;
    manager.requestSerializer.timeoutInterval = 20;
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",nil];
    
    [manager POST:urlString parameters:param progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        successBlock(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failureBlock(task,error);
    }];
}


@end
